package org.puppet.demo.tank.control;

import org.puppet.demo.tank.puppet.Bullet;
import org.puppet.game.World;
import org.puppet.game.control.AbstractController;
import org.puppet.game.control.PuppetUpdateController;
import org.puppet.game.map.SceneMap;

public class BulletController extends AbstractController {

	private Bullet bullet;
	
	private float minX = -40f;
	private float maxX = 360f;
	private float maxY = 180f;
	
	public BulletController(Bullet bullet) {
		this.bullet = bullet;
	}

	public boolean action(Integer eventId, Object e) {

		if (bullet.x < minX) {
			bullet.disappear();
		}if (bullet.x > maxX) {
			bullet.disappear();
		}if (bullet.y > maxY) {
			bullet.explode();
		}
		
/*		List<Puppet> others = World.current.getCurrentView().getPuppets();
		for (Puppet puppet : others) {
			if(puppet instanceof Mario && !puppet.equals(bullet.getTank())){
				if(bullet.collision(puppet)){
					((Mario)puppet).acceY = -0.0028f;
					((Mario)puppet).jump(0f, 0.5f);
					bullet.explode(new Tank[0]);
				}
			}
		}*/

		SceneMap map=World.current.getCurrentView().getSceneMap();
		if(map.collision(bullet)){
			bullet.explode();
		}
		
		return true;
	}

	public int[] lookEvent() {
		return new int[]{PuppetUpdateController.IN_WORLD};
	}

	public Bullet getBullet() {
		return bullet;
	}

	public void setBullet(Bullet bullet) {
		this.bullet = bullet;
	}
	
}
